<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Delete API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'docs-delete.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/docs-delete.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/docs-delete.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/docs-delete.html" rel="nofollow" target="_blank">../en/docs-delete.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="docs.html">Document APIs</a></span>
»
<span class="breadcrumb-node">Delete API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="docs-get.html">« Get API</a>
</span>
<span class="next">
<a href="docs-delete-by-query.html">Delete by query API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="docs-delete"></a>Delete API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Removes a JSON document from the specified index.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-delete-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">DELETE /&lt;index&gt;/_doc/&lt;_id&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-delete-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You use DELETE to remove a document from an index. You must specify the
index name and document ID.</p>
<h5>
<a id="optimistic-concurrency-control-delete"></a>Optimistic concurrency control<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>Delete operations can be made conditional and only be performed if the last
modification to the document was assigned the sequence number and primary
term specified by the <code class="literal">if_seq_no</code> and <code class="literal">if_primary_term</code> parameters. If a
mismatch is detected, the operation will result in a <code class="literal">VersionConflictException</code>
and a status code of 409. See <a class="xref" href="optimistic-concurrency-control.html" title="Optimistic concurrency control">Optimistic concurrency control</a> for more details.</p>
<h5>
<a id="delete-versioning"></a>Versioning<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>Each document indexed is versioned. When deleting a document, the <code class="literal">version</code> can
be specified to make sure the relevant document we are trying to delete is
actually being deleted and it has not changed in the meantime. Every write
operation executed on a document, deletes included, causes its version to be
incremented. The version number of a deleted document remains available for a
short time after deletion to allow for control of concurrent operations. The
length of time for which a deleted document’s version remains available is
determined by the <code class="literal">index.gc_deletes</code> index setting and defaults to 60 seconds.</p>
<h5>
<a id="delete-routing"></a>Routing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>If routing is used during indexing, the routing value also needs to be
specified to delete a document.</p>
<p>If the <code class="literal">_routing</code> mapping is set to <code class="literal">required</code> and no routing value is
specified, the delete API throws a <code class="literal">RoutingMissingException</code> and rejects
the request.</p>
<p>For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">DELETE /twitter/_doc/1?routing=kimchy</pre>
</div>
<div class="console_widget" data-snippet="snippets/1474.console"></div>
<p>This request deletes the tweet with id <code class="literal">1</code>, but it is routed based on the
user. The document is not deleted if the correct routing is not specified.</p>
<h5>
<a id="delete-index-creation"></a>Automatic index creation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>If an <a class="xref" href="docs-index_.html" title="Index API">external versioning variant</a> is used,
the delete operation automatically creates the specified index if it does not
exist. For information about manually creating indices, see
<a class="xref" href="indices-create-index.html" title="Create index API">create index API</a>.</p>
<h5>
<a id="delete-distributed"></a>Distributed<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>The delete operation gets hashed into a specific shard id. It then gets
redirected into the primary shard within that id group, and replicated
(if needed) to shard replicas within that id group.</p>
<h5>
<a id="delete-wait-for-active-shards"></a>Wait for active shards<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>When making delete requests, you can set the <code class="literal">wait_for_active_shards</code>
parameter to require a minimum number of shard copies to be active
before starting to process the delete request. See
<a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">here</a> for further details and a usage
example.</p>
<h5>
<a id="delete-refresh"></a>Refresh<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>Control when the changes made by this request are visible to search. See
<a class="xref" href="docs-refresh.html" title="?refresh"><code class="literal">?refresh</code></a>.</p>
<h5>
<a id="delete-timeout"></a>Timeout<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h5>
<p>The primary shard assigned to perform the delete operation might not be
available when the delete operation is executed. Some reasons for this
might be that the primary shard is currently recovering from a store
or undergoing relocation. By default, the delete operation will wait on
the primary shard to become available for up to 1 minute before failing
and responding with an error. The <code class="literal">timeout</code> parameter can be used to
explicitly specify how long it waits. Here is an example of setting it
to 5 minutes:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">DELETE /twitter/_doc/1?timeout=5m</pre>
</div>
<div class="console_widget" data-snippet="snippets/1475.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-delete-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Required, string) Name of the target index.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;_id&gt;</code>
</span>
</dt>
<dd>
(Required, string) Unique identifier for the document.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-delete-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">if_seq_no</code>
</span>
</dt>
<dd>
(Optional, integer) Only perform the operation if the document has this
sequence number. See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</dd>
<dt>
<span class="term">
<code class="literal">if_primary_term</code>
</span>
</dt>
<dd>
(Optional, integer) Only perform the operation if the document has
this primary term. See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</dd>
<dt>
<span class="term">
<code class="literal">refresh</code>
</span>
</dt>
<dd>
(Optional, enum) If <code class="literal">true</code>, Elasticsearch refreshes the affected shards to make this
operation visible to search, if <code class="literal">wait_for</code> then wait for a refresh to make
this operation visible to search, if <code class="literal">false</code> do nothing with refreshes.
Valid values: <code class="literal">true</code>, <code class="literal">false</code>, <code class="literal">wait_for</code>. Default: <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">routing</code>
</span>
</dt>
<dd>
(Optional, string) Target the specified primary shard.
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">version</code>
</span>
</dt>
<dd>
(Optional, integer) Explicit version number for concurrency control.
The specified version must match the current version of the document for the
request to succeed.
</dd>
<dt>
<span class="term">
<code class="literal">version_type</code>
</span>
</dt>
<dd>
(Optional, enum) Specific version type: <code class="literal">internal</code>, <code class="literal">external</code>,
<code class="literal">external_gte</code>.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_active_shards</code>
</span>
</dt>
<dd>
<p>(Optional, string) The number of shard copies that must be active before
proceeding with the operation. Set to <code class="literal">all</code> or any positive integer up
to the total number of shards in the index (<code class="literal">number_of_replicas+1</code>).
Default: 1, the primary shard.</p>
<p>See <a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">Active shards</a>.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-delete-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/delete.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Delete the JSON document <code class="literal">1</code> from the <code class="literal">twitter</code> index:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">DELETE /twitter/_doc/1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1476.console"></div>
<p>The API returns the following result:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
    "_shards" : {
        "total" : 2,
        "failed" : 0,
        "successful" : 2
    },
    "_index" : "twitter",
    "_type" : "_doc",
    "_id" : "1",
    "_version" : 2,
    "_primary_term": 1,
    "_seq_no": 5,
    "result": "deleted"
}</pre>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="docs-get.html">« Get API</a>
</span>
<span class="next">
<a href="docs-delete-by-query.html">Delete by query API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>